<template>
  <div class="container">
    <div class="container-title">
      <p>企业档案</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>招商管理</el-breadcrumb-item>
        <el-breadcrumb-item>企业管理</el-breadcrumb-item>
        <el-breadcrumb-item>企业档案</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="form">
        <el-form-item
          ><el-input v-model="form.name" placeholder="企业名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.business" filterable placeholder="行业大类">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <div class="block">
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <el-form-item>
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="data-list">
      <div class="data-list-title">
        <span>查询结果列表</span>
        <el-button
          type="success"
          style="background-color: #0bb197"
          @click="addDialog = true"
          >新增</el-button
        >
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="companyName" label="企业名称" align="center">
        </el-table-column>
        <el-table-column prop="business" label="行业大类" align="center">
        </el-table-column>
        <el-table-column prop="childName" label="行业小类" align="center">
        </el-table-column>
        <el-table-column prop="contact" label="联系人" align="center">
        </el-table-column>
        <el-table-column prop="contactTel" label="联系方式" align="center">
        </el-table-column>
        <el-table-column label="企业状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.companyState == 0">正常</span>
            <span v-if="scope.row.companyState == 1">异常</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="area"
          label="企业所属地址"
          align="center"
          width="200"
        >
        </el-table-column
        ><el-table-column label="入驻时间" align="center" width="180">
          <template slot-scope="scope">
            <span>{{ timeTrans(scope.row.startDate) }}</span>
          </template> </el-table-column
        ><el-table-column label="状态" align="center">
          <template slot-scope="scope"
            ><span v-if="scope.row.state == 0">在园</span>
            <span v-if="scope.row.state == 1">退园</span></template
          ></el-table-column
        >
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button @click="edit(scope.row)" type="text" size="small"
              >编辑</el-button
            >
            <el-button @click="deletes(scope.row)" type="text" size="small"
              >删除</el-button
            >
          </template></el-table-column
        >
      </el-table>
      <!-- 页码 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="count"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
      >
      </el-pagination>
    </div>

    <!-- 查看弹窗 -->
    <div class="detail-pop">
      <el-dialog
        title="详细信息"
        :visible.sync="detailDialog"
        width="43%"
        class="detail"
      >
        <div class="detail-content">
          <div class="detail-content-left">
            <ul class="detail-content-ul">
              <li>
                <span>企业名称：</span
                ><span>{{ detailShowData.companyName }}</span>
              </li>
              <li>
                <span>行业大类：</span
                ><span>{{ detailShowData.business }}</span>
              </li>
              <li>
                <span>联系人：</span><span>{{ detailShowData.contact }}</span>
              </li>
              <li>
                <span>企业所属地区：</span
                ><span>{{ detailShowData.area }}</span>
              </li>
              <!-- <li>
                <span>企业简介：</span><span>{{ detailShowData.briefly }}</span>
              </li>
              <li>
                <span>企业文化：</span><span>{{ detailShowData.culture }}</span>
              </li>
              <li>
                <span>产品及服务：</span
                ><span>{{ detailShowData.products }}</span>
              </li> -->
            </ul>
          </div>
          <div class="detail-content-right">
            <ul class="detail-content-ul">
              <li>
                <span>企业状态：</span
                ><span v-if="detailShowData.companyState == 0">正常</span>
                <span v-if="detailShowData.companyState == 1">异常</span>
              </li>
              <li>
                <span>行业小类：</span>
                <span>{{ detailShowData.childName }}</span>
              </li>
              <li>
                <span>联系方式：</span>
                <span>{{ detailShowData.contactTel }}</span>
              </li>
              <li>
                <span>详细地址：</span><span>{{ detailShowData.address }}</span>
              </li>
              <!-- <li>
                <span>企业需求：</span><span>{{ detailShowData.demand }}</span>
              </li>
              <li>
                <span>企业愿景：</span><span>{{ detailShowData.vision }}</span>
              </li> -->
            </ul>
          </div>
        </div>
      </el-dialog>
    </div>

    <!-- 编辑弹窗 -->
    <el-dialog
      title="编辑企业"
      :visible.sync="editDialog"
      width="43%"
      class="edit"
      top="6vh"
    >
      <div class="edit-content">
        <el-form :model="editData">
          <el-form-item label="企业名称">
            <el-input
              v-model="editData.companyName"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="行业大类">
            <el-input
              v-model="editData.business"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人">
            <el-input
              v-model="editData.contact"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业所属地区">
            <el-input
              v-model="editData.area"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业简介">
            <el-input
              v-model="editData.briefly"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业文化">
            <el-input
              v-model="editData.culture"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="产品及服务">
            <el-input
              v-model="editData.products"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-form :model="editData" style="margin-right: 0px">
          <el-form-item label="企业状态">
            <el-select
              v-model="editData.companyState"
              style="width: 320px"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in EnterpriseStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="行业小类">
            <el-input
              v-model="editData.childName"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系方式">
            <el-input
              v-model="editData.contactTel"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input
              v-model="editData.address"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业需求">
            <el-input
              v-model="editData.demand"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业愿景">
            <el-input
              v-model="editData.vision"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialog = false" class="cancel">取 消</el-button>
        <el-button type="primary" @click="editEnsure" class="save"
          >保 存</el-button
        >
      </div>
    </el-dialog>

    <!-- 新增弹窗 -->
    <el-dialog
      title="新增企业"
      :visible.sync="addDialog"
      width="43%"
      class="edit"
      top="6vh"
    >
      <div class="edit-content">
        <el-form :model="addData">
          <el-form-item label="企业名称">
            <el-input
              v-model="addData.companyName"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="行业大类">
            <el-input
              v-model="addData.business"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人">
            <el-input
              v-model="addData.contact"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业所属地区">
            <el-input
              v-model="addData.area"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业简介">
            <el-input
              v-model="addData.briefly"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业文化">
            <el-input
              v-model="addData.culture"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="产品及服务">
            <el-input
              v-model="addData.products"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-form :model="addData" style="margin-right: 0px">
          <el-form-item label="企业状态">
            <el-select
              v-model="addData.companyState"
              style="width: 320px"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in EnterpriseStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="行业小类">
            <el-input
              v-model="addData.childName"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系方式">
            <el-input
              v-model="addData.contactTel"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input
              v-model="addData.address"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业需求">
            <el-input
              v-model="addData.demand"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业愿景">
            <el-input
              v-model="addData.vision"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialog = false" class="cancel">取 消</el-button>
        <el-button type="primary" @click="addEnsure" class="save"
          >保 存</el-button
        >
      </div>
    </el-dialog>

    <!-- 删除弹窗 -->
    <el-dialog :visible.sync="dialogVisible" width="30%" center>
      <span center style="display: block; text-align: center"
        >数据删除将无法恢复，请问确认删除吗？</span
      >
      <span slot="footer" class="dialog-footer" center="true">
        <el-button @click="dialogVisible = false" style="background-color: #ccc"
          >取消</el-button
        >
        <el-button
          type="primary"
          @click="saveFn"
          style="background-color: #0bb197"
          >保存</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import time from "../utils/time";
export default {
  mixins: [time],
  data: function () {
    return {
      page: 1,
      count: 5,
      total: 1,
      options: [],
      form: { name: "", business: "" },
      tableData: [],

      // 下拉框

      // 日历
      value1: [],
      // startTime: "",
      // endTime: "",

      // 查看弹窗数据
      detailShowData: {},
      detailDialog: false,

      // 编辑弹窗
      editDialog: false,
      editData: {},

      // 删除弹窗
      dialogVisible: false,
      delId: 0,

      // 编辑里的企业状态
      EnterpriseStatusOptions: [
        {
          value: 0,
          label: "正常",
        },
        {
          value: 1,
          label: "异常",
        },
      ],

      // 新增弹窗数据
      addDialog: false,
      addData: {
        address: "",
        area: "",
        briefly: "",
        business: "",
        childName: "",
        companyName: "",
        companyState: 0,
        contact: "",
        contactTel: "",
        culture: "",
        demand: "",
        products: "",
        startDate: "",
        state: 0,
        vision: "",
        isDelete: 0,
      },
      flag: true,
    };
  },
  methods: {
    // 渲染
    getData() {
      // this.value1[0] && (this.startTime = this.timeTrans(this.value1[0]));
      // this.value1[1] && (this.endTime = this.timeTrans(this.value1[1]));
      this.$axios({
        url: "/smart/company/query",
        method: "post",
        params: {
          pageNum: this.page,
          pageSize: this.count,
        },
        data: {
          companyName: this.form.name,
          business: this.form.business,
          startTime: this.value1[0],
          endTime: this.value1[1],
        },
      }).then(({ data }) => {
        console.log("lalalal",data);
        if (data.code == "00000") {
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },

    // 查询里的下拉
    getSearch() {
      this.$axios({
        url: "/smart/company/selet/business",
        method: "get",
      }).then(({ data }) => {
        // console.log(data);
        data.data.forEach((v) => {
          let items = {
            value: v,
            label: v,
          };
          this.options.push(items);
        });
      });
    },
    // 查询
    onSearch() {
      this.getData();
    },
    // 重置
    onReset() {
      this.form = {};
      this.value1 = [];
      this.startTime = "";
      this.endTime = "";
      this.getData();
    },

    // 查看
    detail: function (row) {
      this.detailDialog = true;
      console.log(row);
      this.detailShowData = row;
    },
    // 编辑
    edit(row) {
      this.editDialog = true;
      this.editData = { ...row };
    },

    // 编辑里的确认
    editEnsure() {
      this.editDialog = false;
      // let dataGo=this.editData
      this.editData.isDelete = 0;
      console.log(this.editData);
      this.$axios({
        url: "/smart/company/update",
        method: "put",
        data: this.editData,
      }).then(({ data }) => {
        console.log(data);
        if (data.code == "00000") {
          this.getData();
          this.$message.success("编辑成功");
        }
      });
    },
    // 删除
    deletes(row) {
      this.dialogVisible = true;
      this.delId = row.id;
    },
    //删除里的确认
    saveFn() {
      // alert("45");
      this.dialogVisible = false;
      console.log(this.delId);
      this.$axios({
        url: "/smart/company/del/" + this.delId,
        method: "delete",
      }).then(({ data }) => {
        console.log(data);
        if (data.code == "00000") {
          this.getData();
          this.$message.success("删除成功");
        }
      });
    },

    // 新增确认
    addEnsure() {
      this.addDialog = false;
      this.$axios({
        url: "/smart/company/add",
        method: "post",
        data: this.addData,
      }).then(({ data }) => {
        if (data.code == "00000") {
          this.getData();
          this.$message.success("新增成功");
          this.addDat={}
        }
      });
    },
    // 分页
    handleSizeChange(val) {
      this.page = 1;
      this.count = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },
  },
  mounted() {
    this.getData();
    this.getSearch();
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .container-title {
    width: 98%;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      color: #333333;
      font-size: 16px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
    .el-breadcrumb-item {
      color: rgba(148, 148, 148, 0.898039215686275);
      font-size: 12px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
  }
  .search-box {
    width: 98%;
    height: 80px;
    background: #ffffff;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #ffffff;
    border-radius: 5px;
    .el-form {
      width: 98%;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .el-form-item {
        margin-left: 10px;
        margin-bottom: 0;
        .el-select {
          width: 155px;
        }
        .el-button {
          margin: 10px;
        }
        .reset {
          background-color: white;
          color: #c0c4cc;
          border: 1px solid #c0c4cc;
        }
        .reset:hover {
          color: #0bb197;
        }
      }
      .block {
        margin-left: 10px;
      }
      .el-date-editor--datetimerange.el-input__inner {
        width: 310px;
      }
    }
  }
  .data-list {
    width: 98%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;
    .data-list-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        height: 16px;
        font-family: "Arial Normal", "Arial";
        font-weight: 700;
        font-style: normal;
        font-size: 13px;
        color: #3c4145;
      }
    }
    .el-table {
      flex: 1;
      .el-button {
        color: #0bb197;
      }
    }
    .el-pagination {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}

// 查看弹窗
.detail-content-left {
  flex: 1;
  margin-right: 70px;
  .detail-content-ul li {
    height: 40px;
    margin: 15px 0px;
    list-style-type: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
.detail-content-right {
  flex: 1;
  .detail-content-ul li {
    height: 40px;
    margin: 15px 0px;
    list-style-type: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}

// 编辑弹窗
.edit-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.dialog-footer {
  text-align: center;
  .save {
    border: 0px;
    background-color: #0bb197;
  }
  .cancel:hover {
    color: #0bb197;
    border: 1px solid #0bb197;
  }
}
</style>
<style lang="less">
.el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #0bb197;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #0bb197;
  color: #fff;
}

/* 查看弹窗 */
.dev-content-right .cell > img {
  width: 30px;
  height: 100%;
}
.detail-pop {
  .el-dialog__header {
    background-color: #0bb197;
    padding: 10px 20px;
  }
  .el-dialog__title {
    color: white;
  }
  .el-dialog__headerbtn .el-dialog__close {
    color: white;
    font-size: 18px;
  }
  .el-dialog__headerbtn {
    top: 15px;
  }
  .detail-content {
    display: flex;
    justify-content: space-between;
  }
  .el-dialog__body {
    padding: 0px 20px;
  }
}

// 编辑弹窗
.el-form {
  width: 100%;
  margin-right: 20px;
}
.el-dialog__body {
  padding: 0px 20px;
}
.el-form-item {
  margin-bottom: 10px;
}
.el-input__inner:focus {
  border-color: #0bb197;
}
// element.style {
// height: 81px;
// display: flex;
// align-items: center;
// }
.el-table::before {
  height: 0px;
}
</style>
